package com.kejiguan.ui.presenter;


import com.android.volley.error.VolleyError;
import com.android.volley.response.Response;
import com.kejiguan.ui.model.ExhibitionNeItem;
import com.kejiguan.ui.request.GsonRequest;
import com.kejiguan.ui.request.RequestUtil;
import com.kejiguan.ui.response.ActivationExhibitionResponse;
import com.kejiguan.ui.response.RemoveExhibitionResponse;
import com.kejiguan.ui.util.CacheDataUtil;
import com.kejiguan.ui.util.CommonDate;
import com.kejiguan.ui.util.DateFormatUtil;

import org.greenrobot.eventbus.EventBus;

import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by apple on 16/4/17.
 */
public class DisplaySettingFragmentPresenter extends BaseFragmentPresenter{


    public void removeExhibitions(final ExhibitionNeItem exhibitionNeItem) {
        long currentTime = System.currentTimeMillis();
        String currentDate = String.valueOf(currentTime);
        try {
            currentDate = DateFormatUtil.longToString(currentTime, "yyyyMMdd");
        } catch (ParseException e) {
            e.printStackTrace();
        }


        Map<String, String> params = new HashMap<>();
        params.put("requestCode", "714");
        params.put("messageId", currentDate + "S" + currentTime);
        params.put("systemCode", CommonDate.SystemCode);
        params.put("userName", CacheDataUtil.getInstance().getmUser().getUserName());
        params.put("operType", "delete");
        params.put("exhibitionId", exhibitionNeItem.getExhibitionId());
        params.put("exhibitionAreaId", exhibitionNeItem.getExhibitionAreaId());
        params.put("exhibitionName", exhibitionNeItem.getExhibitionName());
        params.put("exhibitionState", "unusing");
        params.put("exhibitionNote", exhibitionNeItem.getExhibitionNote());


        final GsonRequest<RemoveExhibitionResponse> request = new GsonRequest("removeExhibitions", RemoveExhibitionResponse.class, new Response.Listener<RemoveExhibitionResponse>() {
            @Override
            public void onResponse(RemoveExhibitionResponse response) {
                response.setRemovedExhibitionNeItem(exhibitionNeItem);
                EventBus.getDefault().post(response);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

                ActivationExhibitionResponse response=new ActivationExhibitionResponse();
                response.setRetCode("9999");
                response.setRetCode(error.getMessage());
                EventBus.getDefault().post(response);
            }
        });

        RequestUtil.sendRequest(mContext, params, request);
    }

}
